package com.bc.service;



import android.text.TextUtils;
import android.util.Log;

import com.bc.utils.network.GsonUtil;
import com.google.gson.Gson;


public abstract class BaseRequest {
	private static final String TAG = "网络访问";
	private static final String accessLink = "http://www.btc123.com/e/interfaces/tickers.php?";
	private static final Gson gson = GsonUtil.getGsonInstance();

	public BaseRequest() {

	}
	
	public static String toJson(Object obj) {
		return gson.toJson(obj);
	}

	public String getUrl() {
		String path = getPath();
		
		String params = getParams();
		
		if (TextUtils.isEmpty(path) && TextUtils.isEmpty(params)) {
			throw new RuntimeException("访问路径不能为空！");
		}
		
		String endStr = ""; 
		if (!TextUtils.isEmpty(endStr)) {
			endStr += path;
		}
		endStr += params/*URLEncoder.encode(params, "utf-8")*/;
		Log.i(TAG, getClass().getSimpleName() + " 请求路径和参数:" + endStr);
		return accessLink + endStr;
	}
	
	protected abstract String getParams();

	protected abstract String getPath();
}
